package com.bwie.interrogation.controller;

import com.bwie.common.core.domain.Result;
import com.bwie.common.core.utils.poi.ExcelUtil;
import com.bwie.common.core.web.controller.BaseController;
import com.bwie.common.core.web.domain.AjaxResult;
import com.bwie.common.core.web.page.TableDataInfo;
import com.bwie.common.log.annotation.Log;
import com.bwie.common.log.enums.BusinessType;

import com.bwie.interrogation.domain.Drug;
import com.bwie.interrogation.domain.Prescription;
import com.bwie.interrogation.domain.dto.PrescriptionListLlbDto;
import com.bwie.interrogation.service.IprescriptionService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 我的处方Controller
 * 
 * @author ruoyi
 * @date 2025-03-10
 */
@RestController
@RequestMapping("/Interrogation")
public class prescriptionController extends BaseController
{
    @Autowired
    private IprescriptionService prescriptionService;
    /**
     * 查询我的处方列表
     */
    @GetMapping("/listPrescription")
    public TableDataInfo list(Prescription prescription)
    {
        startPage();
        List<Prescription> list = prescriptionService.selectprescriptionList(prescription);
        return getDataTable(list);
    }
    /**
     * 导出我的处方列表
     */
//    @Log(title = "我的处方", businessType = BusinessType.EXPORT)
//    @PostMapping("/exportPrescription")
//    public void export(HttpServletResponse response, Prescription prescription)
//    {
//        List<Prescription> list = prescriptionService.selectprescriptionList(prescription);
//        ExcelUtil<Prescription> util = new ExcelUtil<Prescription>(Prescription.class);
//        util.exportExcel(response, list, "我的处方数据");
//    }

    /**
     * 获取我的处方详细信息
     */

    @GetMapping(value = "/idPrescription/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(prescriptionService.selectprescriptionById(id));
    }

    /**
     * 新增我的处方
     */
    @Log(title = "我的处方", businessType = BusinessType.INSERT)
    @PostMapping("/addPrescription")
    @Transactional
    public void addPrescription(@RequestBody PrescriptionListLlbDto prescription){
        prescriptionService.addPrescription(prescription);
    }

    /**
     * 修改我的处方
     */
    @Log(title = "我的处方", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Prescription prescription)
    {
        return toAjax(prescriptionService.updateprescription(prescription));
    }

    /**
     * 删除我的处方
     */
    @Log(title = "我的处方", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(prescriptionService.deleteprescriptionByIds(ids));
    }
    /**
     * 查询药品列表
     */
    @PostMapping("/prescriptionListDrug")
    public Result prescriptionListLlb(){
        List<Drug> list = prescriptionService.prescriptionList();
        return Result.success(list);
    }
}
